package com.onlinescxhz.demo.controller;


import com.onlinescxhz.demo.Mapper.UserMapperDao;
import com.onlinescxhz.demo.common.Result;
import com.onlinescxhz.demo.pojo.User;
import com.onlinescxhz.demo.utils.TokenUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController

@CrossOrigin  //跨域获取数据
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserMapperDao userMapperDao;
    @PostMapping("/login")
    public Result login(@RequestBody User lsuser){
        System.out.println("login");
        User user=null;
        user=userMapperDao.findbyzhpwd(lsuser);
        if(user==null){
            return  Result.error();
        }
        String token= TokenUtils.createtoken(lsuser.getAccount(),lsuser.getPassword());
        System.out.println(lsuser.toString());
        return  Result.seccess(user,token);  //传对象  res.data.属性code object
    }
    /**
     * 测试
     * @return
     */
    @GetMapping("/sjt")
    public Result TZindex(){
        List<User> users=userMapperDao.getAll();

        return   Result.seccess(users);
    }
}
